using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace Tryit.Models
{
    public class MaterialElement : INotifyPropertyChanged
    {
        private string _elementName;
        private double _value;

        public string ElementName
        {
            get => _elementName;
            set => SetProperty(ref _elementName, value);
        }

        public double Value
        {
            get => _value;
            set => SetProperty(ref _value, value);
        }

        public MaterialElement()
        {
            _elementName = "";
            _value = 0.0;
        }

        public MaterialElement(string elementName, double value)
        {
            _elementName = elementName;
            _value = value;
        }

        public event PropertyChangedEventHandler? PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        protected bool SetProperty<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
        {
            if (Equals(field, value)) return false;
            field = value;
            OnPropertyChanged(propertyName);
            return true;
        }
    }
} 